package com.marchsoft.musicalstore.service;

import com.marchsoft.musicalstore.entity.StuCourse;
import com.marchsoft.musicalstore.entity.User;
import com.marchsoft.musicalstore.repository.UserRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 云
 * Date: 2019-11-22
 * Time: 19:36
 */
@Service
public class UserInfo {
    @Autowired
    UserRepository userRepository;

    //通过id获取个人课程信息
    public User getPerInfo(int id){
        return userRepository.findById(id);
    }

    //更新用户信息
    public User update(String head_img, String nickName,String phone,String password,int id){
         if("".equals(head_img)){
             return null;
         }else if("".equals(nickName)){
          return null;
        }
         else if("".equals(password)){
             return null;
         }
         else if("".equals(phone)){
            return null;
        }else{
             User user=getPerInfo(id);
             user.setHeadImg(head_img);
             user.setNickName(nickName);
             user.setPhone(phone);
             user.setPassword(password);
             User save = userRepository.save(user);
             return save;
         }

//        System.out.println(head_img+"----------------------");
//        return userRepository.update(head_img,nickName,phone,password,id);
    }
}
